package com.lyc.speechtranscriber;

public class BytesUtils {
    static void shortsToBytes(int shortsSize, short[] buffer, byte[] audioData) {
        for (int i = 0; i < shortsSize; i++) {
            byte[] bytes = getBytes(buffer[i]);
            audioData[i * 2] = bytes[0];
            audioData[i * 2 + 1] = bytes[1];
        }
    }

    static byte[] getBytes(short s) {
        byte[] buf = new byte[2];
        for (int i = 0; i < buf.length; i++) {
            buf[i] = (byte) (s & 0x00ff);
            s >>= 8;
        }
        return buf;
    }

}
